"""
@Project ：HD_project 
@File    ：year_plan.py
@IDE     ：PyCharm 
@Author  ：靓仔
@Date    ：2023/11/28 0028 16:44 
"""
import json

import requests

from utils.new_time import get_time_of_day, new_time

headers = {
    'Accept': 'application/json, text/plain, */*',
    'Accept-Encoding': 'gzip, deflate',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Autothrowerror': 'true',
    'Connection': 'keep-alive',
    'Content-Length': '80',
    'Content-Type': 'application/json;charset=UTF-8',
    'Ctp-T-Code': '0002200000080659',
    'Host': '10.6.10.110',
    'Origin': 'http://10.6.10.110',
    'Ratio': '945*1512',
    'Referer': 'http://10.6.10.110/',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) '
                  'Chrome/119.0.0.0 Safari/537.36',
    'Cookie': 'cs_cStorage_=1; _account=%7B%22account%22%3A%22SuperAdmin%22%2C%22password%22%3A%22V64RK%5C%5C68%5C%5C65%5C%5C6c%5C%5C6c%5C%5C6f%5C%5CLYYJD%22%2C%22ctpTCode%22%3Anull%2C%22encode%22%3Atrue%7D; OWASP_CSRFTOKEN=0CBK-BBVK-QEF4-1DTQ-8DS0-D09T-I56N-KG6S; userName=""; userPwd=""; _isLogout=false; Authorization=""; province_flag=; access-token=eyJhbGciOiJIUzUxMiJ9.eyJhY2NvdW50IjoieWFuemhpIiwidXNlcklkIjoiOEQzN0I2RkM0QUE4NDdCM0I0MDU1NDM1QjkyREVEQTEiLCJlbXBsb3llZUlkIjoiNzI3RkQyQTk5QkEwNDQ5MEI3QTcwNTcwQUVENDgxRkYiLCJlbXBsb3llZU5hbWUiOiLpopzlgLwiLCJvcmdJZCI6IjIwMDAwMDQ4Iiwib3JnQ29kZSI6IjIwMDAwMDQ4Iiwib3JnTmFtZSI6IuazleW-i-WQiOinhOmDqCIsInRoaXJkU3lzdGVtTmFtZSI6IkpBRFAiLCJzeXN0ZW1OYW1lIjoibnVsbCIsInN1YiI6IuminOWAvCIsImlhdCI6MTcwMTE2MzI5OSwiZXhwIjoxNzAxMTkwNjYwLCJyZWZyZXNoSW50ZXJ2YWwiOjQ1MCwianRpIjoiMTY1ZWFmZmMtZjRiYy00NzJkLWFiMGYtN2U4YmNiMzIzZDMxIiwicmVmcmVzaERhdGUiOjE3MDExNjM2NjAwMDB9.YtdJUW3hEjyV1Z75TxMngL50a4FtMXtxSCBJicc68WtuNZyiew6ZXvWjwil2CNbtr-THcTXElHz-_OnZMF87rg'
}


def get_annual_summary_todo_data():
    url = "http://10.6.10.110/bd-grsx-api/todo/page/collapse"
    data = {"bllx": "2", "userId": "68D37B6FC4AA847B3B4055435B92DEDA1", "xtbs": "10011006"}

    response = requests.post(url=url, json=data, headers=headers)
    response.raise_for_status()  # 检查请求是否成功
    res = response.json()
    # 使用列表推导式提取所有待办事项的ID
    todo_ids = [a["id"] for result in res.get("result", []) for a in result.get("datas", {}).get("list", [])]
    for todo_id in todo_ids:
        plan_url = "http://10.6.10.110/bd-grsx-api/todo/queryTodoBytodoId/" + todo_id
        plan_res = json.loads(requests.post(url=plan_url, json={}, headers=headers).text)
        plan_id = plan_res["result"]["docId"]
        activityDefId = plan_res["result"]["activityDefId"]
        activityInstId = plan_res["result"]["activityInstId"]
        docId = plan_res["result"]["docId"]
        preTodo = plan_res["result"]["preTodo"]
        show_data = {"xtbs": "10011006", "docType": "4",
                     "data": {"docId": docId, "templateId": "56F0B78C88934521A4A049701651300B", "templateType": "4",
                              "activityDefId": activityDefId}}
        show_url = "http://10.6.10.110/zdgl-api/common/data/show"
        show_res = json.loads(requests.post(url=show_url, json=show_data, headers=headers).text)
        print(show_res)


if __name__ == '__main__':
    print(get_annual_summary_todo_data())
